<?php
require_once ("../src/db/connectdatabase.php");

function getQuestions() {
	$con = new ConnectDB();
	$tbl = "questioncard";
	$fn = array('idques', 'quesinfocard', 'datecreate');
	$condetion = array();
	return $con -> getvalueorderby($tbl, $fn, $condetion, 'datecreate');
}


function int_to_date($int)
{
    $time  = date("d/m/Y", $int);
    return $time;
}	
$arrlistquestion = getQuestions();
?>
<style>
.listquestionview table {
	width: 850px;
	max-width: 850px;
}

table td {
	margin-top: 2px;
	border: 1px solid;
	border-radius: 2px 2px 2px 2px;
}

table tr:hover td {
	background: #FFC;
}

.title {
	text-align: center;
	background-color: #0088cc;
	min-height: 40px;
	-moz-border-radius: 8px 8px 0px 0px;
	-webkit-border-radius: 8px 8px 0px 0px;
	border-radius: 8px 8px 0px 0px;
	color: #FFF;
}

.stylequestionname {
	width: 450px;
}

.styledatecreatequestion {
	width: 100px;
	max-width: 100px;
	text-align: center;
}

.styleacctionquestion {
	width: 150px;
	text-align: center;
	max-width: 150px;
}

.namequestionline {
	text-align: left;
	padding-left: 5px;
	padding-right: 5px;
}

table td img {
	cursor: pointer;
}

.nameformquestion {
	background: url(../images/bg-login.png);
	-moz-border-radius: 2px 2px 2px 2px;
	-webkit-border-radius: 2px 2px 2px 2px;
	border-radius: 2px 2px 2px 2px;
}

.linequestiondate {
	text-align: center;
}

.stylestt {
	width: 70px;
}
</style>

<h3>Câu Hỏi Thường Gặp Khi Làm Thẻ</h3>
<div><a href="admin.php?content=quanlythetindung&&as=them-cau-hoi-the"><img src="../images/icon-add.jpg" title="Thêm Câu Hỏi Khi Làm Thẻ Tín Dụng" />Thêm Câu Hỏi</a></div>
<div class="listquestionview">
	<table>
    	<tr>
        	<th class="stylestt title">STT</th>
        	<th class="stylequestionname title">Câu Hỏi</th>
            <th class="styledatecreatequestion title">Ngày C.Nhật</th>
            <th class="styleacctionquestion title">Chức Năng</th>
        </tr>
  		<?php
		if(count($arrlistquestion) > 0) {
			for($i = 0; $i < count($arrlistquestion); $i++) {
		?>
        <tr>
        	<td class="nameformquestion" align="center"><?php echo($i + 1) ?></td>
        	<td class="nameformquestion namequestionline"><?php echo($arrlistquestion[$i][1]) ?></td>
            <td class="nameformquestion linequestiondate"><?php echo(int_to_date($arrlistquestion[$i][2])) ?></td>
            <td class="nameformquestion linequestiondate"><img idvalue="<?php echo($arrlistquestion[$i][0]) ?>" class="class-editquestion-link" src="../images/icon-edit.gif" title="Chỉnh Sửa <?php echo($arrlistquestion[$i][1]) ?>" />&nbsp; | &nbsp;<img idvalue="<?php echo($arrlistquestion[$i][0]) ?>" class="class-deletequestion-link" src="../images/icon-delete.gif" title="Xóa <?php echo($arrlistquestion[$i][1]) ?>" /></td>
        </tr>
        <?php
			}
		} else {
			?>
        <tr><th colspan="3">Chưa có danh sách câu hỏi nào khi làm thẻ</th></tr>
            <?php
		}
		?>
        
    </table>
</div>
<div><a href="admin.php?content=quanlythetindung&&as=them-cau-hoi-the"><img src="../images/icon-add.jpg" title="Thêm Câu Hỏi Khi Làm Thẻ Tín Dụng" />Thêm Câu Hỏi</a></div>

<script>
$(document).on('click', '.class-editquestion-link', function(e) {
		elem = $(this)
		var idquestion = elem.attr('idvalue');
		window.location= 'admin.php?content=quanlythetindung&&as=edit-question-card&&id=' + idquestion;
});
$(document).on('click', '.class-deletequestion-link', function(e) {
	elem = $(this)
	var idquestion = elem.attr('idvalue');
	if(confirm("Bạn có muốn xóa?")) {
		$.ajax({
			url: "../src/ajax/ajaxquestioncard.php",
			type: "post",
			data: {act:'del', cauhoiid: idquestion},
			dataType:"json",
			success: function(data) {
				if(data == true) {
					elem.parent().parent().fadeOut(300, function(){elem.parent().parent().remove();});
				} else {
					alert("Cập nhật dữ liệu không thành công");
				}
			}
		});
	}
});
</script>
